/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2011
 */

package com.tech15.core.model;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import javacommon.base.BaseEntity;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Max;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.Length;

/**
 * @author 胡作正 email:zuozhenghu@sina.com
 * @version 1.0
 * @since 1.0
 */


@Entity
@Table(name = "SYS_MODULE")
public class Module extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//alias
	public static final String TABLE_ALIAS = "系统模块";
	public static final String ALIAS_MDID = "序号";
	public static final String ALIAS_NAME = "名称";
	public static final String ALIAS_MDNO = "功能编号";
	public static final String ALIAS_REMARK = "备注";
	public static final String ALIAS_LAYER = "层";
	public static final String ALIAS_PID = "父序号";
	public static final String ALIAS_URL = "url";
	public static final String ALIAS_FIXED = "固定（1 固定 0 菜单）";
	
	//date formats
	

	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
    /**
     * 序号       db_column: MDID 
     */ 	
	
	private Long mdid;
    /**
     * 名称       db_column: NAME 
     */ 	
	@Length(max=32)
	private java.lang.String name;
    /**
     * 功能编号       db_column: MDNO 
     */ 	
	@Length(max=50)
	private java.lang.String mdno;
    /**
     * 备注       db_column: REMARK 
     */ 	
	@Length(max=200)
	private java.lang.String remark;
    /**
     * 层       db_column: LAYER 
     */ 	
	@Max(127)
	private Integer layer;
    /**
     * 父序号       db_column: PID 
     */ 	
	
	private Long pid;
    /**
     * url       db_column: URL 
     */ 	
	@Length(max=200)
	private java.lang.String url;
    /**
     * 固定（1 固定 0 菜单）       db_column: FIXED 
     */ 	
	@Length(max=1)
	private java.lang.String fixed;
	/**
     * 类型       db_column: TYPE 
     */ 	
	@Max(127)
	private Integer type;
	/**
     * 排序       db_column: SORTNO 
     */ 	
	@Max(127)
	private Integer sortno;
	/**
     * 系统id       db_column: DID 
     */ 	
	private java.lang.Integer appid;
	
	private Integer isshfw;
	//columns END
	
	@Column(name = "ISSHFW", unique = false, nullable = true, insertable = true, updatable = true, length = 2)
	public Integer getIsshfw() {
		return isshfw;
	}

	public void setIsshfw(Integer isshfw) {
		this.isshfw = isshfw;
	}


	public Module(){
	}

	public Module(
		Long mdid
	){
		this.mdid = mdid;
	}

	public void setMdid(Long value) {
		this.mdid = value;
	}
	
	@Id @GeneratedValue(generator="custom-id")
	@GenericGenerator(name="custom-id", strategy = "increment")
	@Column(name = "MDID", unique = true, nullable = false, insertable = true, updatable = true, length = 22)
	public Long getMdid() {
		return this.mdid;
	}
	
	@Column(name = "NAME", unique = false, nullable = true, insertable = true, updatable = true, length = 32)
	public java.lang.String getName() {
		return this.name;
	}
	
	public void setName(java.lang.String value) {
		this.name = value;
	}
	
	@Column(name = "MDNO", unique = false, nullable = true, insertable = true, updatable = true, length = 50)
	public java.lang.String getMdno() {
		return this.mdno;
	}
	
	public void setMdno(java.lang.String value) {
		this.mdno = value;
	}
	
	@Column(name = "REMARK", unique = false, nullable = true, insertable = true, updatable = true, length = 200)
	public java.lang.String getRemark() {
		return this.remark;
	}
	
	public void setRemark(java.lang.String value) {
		this.remark = value;
	}
	
	@Column(name = "LAYER", unique = false, nullable = true, insertable = true, updatable = true, length = 2)
	public Integer getLayer() {
		return this.layer;
	}
	
	public void setLayer(Integer value) {
		this.layer = value;
	}
	
	@Column(name = "PID", unique = false, nullable = true, insertable = true, updatable = true, length = 22)
	public Long getPid() {
		return this.pid;
	}
	
	public void setPid(Long value) {
		this.pid = value;
	}
	
	@Column(name = "URL", unique = false, nullable = true, insertable = true, updatable = true, length = 200)
	public java.lang.String getUrl() {
		return this.url;
	}
	
	public void setUrl(java.lang.String value) {
		this.url = value;
	}
	
	@Column(name = "FIXED", unique = false, nullable = true, insertable = true, updatable = true, length = 1)
	public java.lang.String getFixed() {
		return this.fixed;
	}
	
	public void setFixed(java.lang.String value) {
		this.fixed = value;
	}
	
	@Column(name = "TYPE", unique = false, nullable = true, insertable = true, updatable = true, length = 2)
	public Integer getType() {
		return this.type;
	}
	
	public void setType(Integer value) {
		this.type = value;
	}
	@Column(name = "SORTNO", unique = false, nullable = true, insertable = true, updatable = true, length = 2)
	public Integer getSortno() {
		return this.sortno;
	}
	
	public void setSortno(Integer value) {
		this.sortno = value;
	}
	
	@Column(name = "APPID", unique = false, nullable = true, insertable = true, updatable = true, length = 3)
	public java.lang.Integer getAppid() {
		return this.appid;
	}
	
	public void setAppid(java.lang.Integer value) {
		this.appid = value;
	}
	
	
	private Set modules = Collections.synchronizedSet(new LinkedHashSet(0));
	public void setModules(Set<Module> module){
		this.modules = module;
	}
	
	@OneToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "module")
	@OrderBy(value = "sortno ASC")
	public Set<Module> getModules() {
		return modules;
	}
	
	private Set moduleFunctions = Collections.synchronizedSet(new LinkedHashSet(0));
	public void setModuleFunctions(Set<ModuleFunction> moduleFunction){
		this.moduleFunctions = moduleFunction;
	}
	
	@OneToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "module")
	public Set<ModuleFunction> getModuleFunctions() {
		return moduleFunctions;
	}
	
	private Module module;
	public void setModule(Module module){
		this.module = module;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumns({
		@JoinColumn(name = "PID",nullable = false, insertable = false, updatable = false) 
	})
	public Module getModule() {
		return module;
	}

	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
			.append("Mdid",getMdid())
			.append("Name",getName())
			.append("Mdno",getMdno())
			.append("Remark",getRemark())
			.append("Layer",getLayer())
			.append("Pid",getPid())
			.append("Url",getUrl())
			.append("Fixed",getFixed())
			.toString();
	}
	
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getMdid())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof Module == false) return false;
		if(this == obj) return true;
		Module other = (Module)obj;
		return new EqualsBuilder()
			.append(getMdid(),other.getMdid())
			.isEquals();
	}
	
	private Long level;
	private Long isAuth;
	
	private String my;
	private String dept;
	private String pg;
	private List<Module> child;
	private String childAuthJson;
	
	@Transient
	public String getChildAuthJson() {
		return childAuthJson;
	}

	public void setChildAuthJson(String childAuthJson) {
		this.childAuthJson = childAuthJson;
	}

	@Transient
	public List<Module> getChild() {
		return child;
	}

	public void setChild(List<Module> child) {
		this.child = child;
	}

	@Transient
	public String getDept() {
		return dept;
	}

	public void setDept(String dept) {
		this.dept = dept;
	}
	@Transient
	public String getMy() {
		return my;
	}

	public void setMy(String my) {
		this.my = my;
	}
	@Transient
	public String getPg() {
		return pg;
	}

	public void setPg(String pg) {
		this.pg = pg;
	}
	@Transient
	public Long getIsAuth() {
		return isAuth;
	}

	public void setIsAuth(Long isAuth) {
		this.isAuth = isAuth;
	}
	@Transient
	public Long getLevel() {
		return level;
	}

	public void setLevel(Long level) {
		this.level = level;
	}
}

